﻿using iemtm.WeChat.Core;
using iemtm.WeChat.Core.Managers;
using iemtm.WeChat.Web.Entry.Areas.Admin.Model;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace iemtm.WeChat.Web.Entry.Areas.Admin.Controllers
{
    [Area("Admin")]
    [Route("/[controller]/[action]")]
    public class AnnounceTeleAuditController : Controller
    {
        private readonly IWorkManager _workManager;
        //  private readonly IUserManager _userManager;
        //  private readonly IGeneratorManager _generatorManager;
        private readonly IInfoManager _infoManager;

        public AnnounceTeleAuditController(IWorkManager workManager
             //  , IUserManager userManager
             //   , IGeneratorManager generatorManager
             , IInfoManager infoManager
            )
        {
            _workManager = workManager;
            //  _userManager = userManager;
            // _generatorManager = generatorManager;
            _infoManager = infoManager;
        }

        public IActionResult Index()
        {
            return View();
        }
        /// <summary>
        /// 审核页面
        /// </summary>
        /// <param name="GenImg1">审核单Id</param>
        /// <param name="AnnounceStatus">状态</param>
        /// <param name="AnnounceCode">工单号</param>
        /// <returns></returns>
        public ActionResult TeleAduit(string GenImg1, int AnnounceStatus, string AnnounceCode)
        {
            ViewBag.GenImg1 = GenImg1;
            ViewBag.AnnounceStatus = AnnounceStatus;
            ViewBag.AnnounceCode = AnnounceCode;
            //Console.WriteLine("JobNumber::" + AnnounceCode);
            return View();
        }

        /// <summary>
        /// 工单详情页面
        /// </summary>
        /// <param name="annouceCode"></param>
        /// <returns></returns>
        public async Task<ActionResult> Detail(string annouceCode, int Id)
        {

            AnnouceTeleAduitDetailModel model = new AnnouceTeleAduitDetailModel();
            var LoginInfo = _workManager.CurrentUser;
            //model.AnnounceList = dbContext.Queryable<AnnounceList>().First(c => c.AnnounceCode == annouceCode && c.PrjCode == LoginInfo.PrjCode);
            model.AnnounceList = await _infoManager.GetAnnFirstOrDefaultAsync(c => c.AnnounceCode == annouceCode && c.PrjCode == LoginInfo.PrjCode);

            //model.BaseStationTTCode = dbContext.Queryable<BaseStation>().First(c => c.BaseStationCode == model.AnnounceList.BaseStationCode)?.BaseStationTTCode;
            model.BaseStationTTCode = (await _infoManager.GetBaseStationFirstAsync(c => c.BaseStationCode == model.AnnounceList.BaseStationCode))?.BaseStationTTCode;

            //model.AnnounceAudit = dbContext.Queryable<AnnounceAudit>().First(c => c.Id == Id);
            model.AnnounceAudit = await _infoManager.GetAnnounceAuditFirstAsync(c => c.Id == Id);
            model.Id = Id;
            // model.GensetNum = dbContext.Queryable<Generator>().First(c => c.GeneratorCode == model.AnnounceList.RegisteredGenset)?.GensetNum ?? model.AnnounceList.RegisteredGenset;
            model.GensetNum = MemoryEntity.gBuffGen.All.Values.FirstOrDefault(c => c.GeneratorCode == model.AnnounceList.RegisteredGenset)?.GensetNum ?? model.AnnounceList.RegisteredGenset;

            model.RoleCode = LoginInfo.RoleCode;
            //model.AnnFee = dbContext.Queryable<AnnFee>().First(c => c.AnnounceCode == model.AnnounceList.AnnounceCode);
            model.AnnFee = await _infoManager.GetAnnFeeFirstAsync(c => c.AnnounceCode == model.AnnounceList.AnnounceCode);


            return View(model);
        }
    }
}
